<!-- 培训申请 -->
<template>
  <view>
    <u-form
      :model="model"
      :rules="rules"
      ref="form"
      labelPosition="top"
      labelWidth="auto"
      :labelStyle="{
        fontSize: '14px',
        color: '#B2B2B2',
        lineHight: '20px'
      }"
    >
      <view class="basic-style">
        <view class="basic-title basic-border">基本信息</view>
        <u-form-item label="单据编号" prop="billNo" required>
          <u--input v-model="model.billNo" disabled></u--input>
        </u-form-item>
				<u-form-item label="申请时间" required>
				  <u--input v-model="model.createTime" disabled suffixIcon="calendar-fill" :suffixIconStyle="{color: '#B2B2B2'}" placeholder="请选择日期"></u--input>
				</u-form-item>
        <u-form-item label="申请人" prop="handlerId" required>
          <h-select-person-input
            style="width: 100%"
            disabled
            v-model="model.handlerId"
            placeholder="请选择申请人"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            objectField="model.handlerId"
          ></h-select-person-input>
        </u-form-item>
        <u-form-item label="申请部门" prop="applyDeptId" required>
          <h-select-depart-input
            disabled
            v-model="model.applyDeptId"
            :departName="model.proposerDeptText"
            placeholder="请选择部门"
            border="surround"
            style="width: 100%"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            :title.sync="model.proposerDeptText"
          ></h-select-depart-input>
        </u-form-item>
        <u-form-item label="申请人所属团队" prop="costTeamId" required>
          <h-select-team-input
            style="width: 100%"
            v-model="model.costTeamId"
            objectField="model.costTeamId"
            placeholder="请选择申请人所属团队"
            border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
            :tdlx="3"
          />
        </u-form-item>
      </view>
			<view class="basic-style">
			  <view class="basic-title basic-border">培训信息</view>
				<!-- 变更作废选择信息 -->
				<template v-if="trainingType != 'apply'">
					<u-form-item label="选择培训档案" prop="finalId" required>
						<h-select-hr-training-change-input
							style="width: 100%"
							v-model="model.finalId"
							objectField="model.finalId"
							placeholder="请选择选择培训档案"
							border="surround"
							suffixIcon="arrow-down-fill"
							@input="handleChangeBack"
							:suffixIconStyle="{color: '#B2B2B2'}" />
					</u-form-item>
				</template>
				<u-form-item label="培训分类" prop="trainingCategory" required>
				  <h-select-input-tag
				    class="w-100"
				    v-model="model.trainingCategory"
						:disabled="trainingType != 'apply'"
				    objectField="model.trainingCategory"
				    placeholder="请选择培训分类"TrainingPersonInfo
				    border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
				    dictName="training_category"
				  ></h-select-input-tag>
				</u-form-item>
				<u-form-item label="培训目的" prop="trainingObjective" required>
				  <u--input placeholder="请输入培训目的" :disabled="trainingType == 'cancel'" :maxlength="50" v-model="model.trainingObjective"></u--input>
				</u-form-item>
				<u-form-item label="培训地点" prop="trainingAddress" required>
				  <u--input placeholder="请输入培训地点" :disabled="trainingType == 'cancel'" :maxlength="50" v-model="model.trainingAddress"></u--input>
				</u-form-item>
				<u-form-item label="获得证书名称" prop="certificateName" required>
				  <u--input placeholder="请输入获得证书名称" :disabled="trainingType == 'cancel'" :maxlength="50" v-model="model.certificateName"></u--input>
				</u-form-item>
				<u-form-item label="培训开始日期" prop="trainingStartDate" required>
				  <h-time-select
				    mode="date"
						:disabled="trainingType == 'cancel'"
						:maxDate="model.trainingEndDate?((new Date(model.trainingEndDate)).getTime()) - 86400000:(new Date(new Date().getFullYear() + 10, new Date().getMonth(), new Date().getDate())).getTime()"
				    v-model="model.trainingStartDate"
				    placeholder="请选择培训开始日期"
				    border="surround"
				    suffixIcon="calendar-fill"
				    :suffixIconStyle="{ color: '#B2B2B2' }"
				  ></h-time-select>
				</u-form-item>
				<u-form-item label="培训结束日期" prop="trainingEndDate" required>
				  <h-time-select
				    mode="date"
						:disabled="trainingType == 'cancel'"
				    v-model="model.trainingEndDate"
				    placeholder="请选择培训结束日期"
				    border="surround"
				    suffixIcon="calendar-fill"
						:minDate="model.trainingStartDate?((new Date(model.trainingStartDate)).getTime()) + 86400000:315504000000"
				    :suffixIconStyle="{ color: '#B2B2B2' }"
				  ></h-time-select>
				</u-form-item>
				<u-form-item label="服务开始日期" prop="serviceStartDate" required>
				  <h-time-select
				    mode="date"
						:disabled="trainingType == 'cancel'"
				    v-model="model.serviceStartDate"
				    placeholder="请选择服务开始日期"
				    border="surround"
				    suffixIcon="calendar-fill"
				    :suffixIconStyle="{ color: '#B2B2B2' }"
						@change="handleServiceLimitBack"
				  ></h-time-select>
				</u-form-item>
				<u-form-item label="培训服务期限" prop="trainingServiceLimit" required>
				  <h-select-input-tag
				    class="w-100"
						:disabled="trainingType == 'cancel'"
				    v-model="model.trainingServiceLimit"
				    objectField="model.trainingServiceLimit"
				    placeholder="请选择培训服务期限"
				    border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
				    dictName="training_service_limit"
						@change="handleServiceLimitBack"
				  ></h-select-input-tag>
				</u-form-item>
				<u-form-item label="服务结束日期" prop="serviceEndDate" required>
				  <h-time-select
						disabled
				    mode="date"
				    v-model="model.serviceEndDate"
				    placeholder="请选择服务结束日期"
				    border="surround"
				    suffixIcon="calendar-fill"
				    :suffixIconStyle="{ color: '#B2B2B2' }"
				  ></h-time-select>
				</u-form-item>
				<u-form-item label="培训费用(元/人)" prop="trainingFee" required>
					<h-money-input placeholder="请输入培训费用" :disabled="trainingType == 'cancel'" v-model="model.trainingFee" @blur="handleTrainingFeeChange"></h-money-input>
				</u-form-item>
				<u-form-item label="培训费用合计(元)" prop="trainingFeeTotal" required>
					<h-money-input disabled placeholder="请输入培训费用合计" v-model="model.trainingFeeTotal"></h-money-input>
				</u-form-item>
				</u-form-item>
				<view style="font-size: 14px; color: rgb(178, 178, 178); padding-bottom: 5px;">培训人员</view>
				<view class="space-y-1" v-if="trainingType != 'cancel'">
				  <u-button size="small" type="primary" @click="handleAddMaterial">新增</u-button>
				</view>
				<template v-if="formData && formData.length">
					<u-collapse>
					  <u-collapse-item :title="item.employeeId_dictText?item.employeeId_dictText: ''" v-for="(item, index) in formData" :key="index">
					    <TrainingPersonInfo
					      :item="item"
								:trainingType="trainingType"
					      :index="index"
					      @remove="handleRemoveForm"
					      @copy="handleCopyForm"
					    />
					  </u-collapse-item>
					</u-collapse>
				</template>
				<template v-else>
					<u-empty
						mode="data"
						text="暂无数据"
						icon="/static/empty/data.png"
					>
					</u-empty>
				</template>
				<u-form-item label="备注" prop="remark">
				  <u--textarea :confirm-type="null" :disabled="trainingType != 'apply'" v-model="model.remark" count :maxlength="500" placeholder="请输入备注"></u--textarea>
				</u-form-item>
				<template v-if="trainingType == 'change'">
					<u-form-item label="变更描述" prop="changeRemark" required>
						<!-- #ifdef H5 -->
						<u--textarea confirm-type="done" :maxlength="500" v-model="model.changeRemark" placeholder="请输入变更描述"></u--textarea>
						<!-- #endif -->
						<!-- #ifndef H5 -->
						<u--textarea :confirm-type="null" :maxlength="500" count v-model="model.changeRemark" placeholder="请输入变更描述"></u--textarea>
						<!-- #endif -->
					</u-form-item>
				</template>
				<template v-if="trainingType == 'cancel'">
					<u-form-item label="作废描述" prop="invalidRemark" required>
						<!-- #ifdef H5 -->
						<u--textarea confirm-type="done" :maxlength="500" v-model="model.invalidRemark" placeholder="请输入作废描述"></u--textarea>
						<!-- #endif -->
						<!-- #ifndef H5 -->
						<u--textarea :confirm-type="null" :maxlength="500" count v-model="model.invalidRemark" placeholder="请输入作废描述"></u--textarea>
						<!-- #endif -->
					</u-form-item>
				</template>
			</view>
      <view class="basic-style">
        <view class="basic-title basic-border">附件信息</view>
        <view class="py-1 space-y-1" style="width: 100%">
          <view style="color: red">
            提示：（附件要求：1、业主盖章版合同；2、工程量清单；3、技术要求等），请等待附件上传完成，再点击保存，否则附件无法保存成功！
          </view>
          <h-upload-file v-model="model.attachment" :isIcon="false"></h-upload-file>
          <file-list v-if="model.attachment" v-model="model.attachment" :isDelete="true"></file-list>
        </view>
      </view>
			<view class="space-x-1 px-1 btn_position">
				<u-button :disabled="isSubmit" type="primary" :plain="true" text="保存" @click="onDraft"></u-button>
				<u-button :disabled="isSubmit"  type="primary"  text="保存并提交" @click="onSubmit"></u-button>
			</view>
			<view style="height: 100rpx;"></view>
    </u-form>
		<u-toast ref="uToast"></u-toast>
		<ProcessNodeConfiguration ref="processConfig" @ok="onOk"></ProcessNodeConfiguration>
  </view>
</template>

<script>
import { mapState } from 'vuex'
import moment from 'moment'
import { gainBillNo, add, edit, info } from '@/api/hr/ErpHrTrainingApplyForm'
import { erpmngUserId,erpmngUserIds } from '@/api/index.js'
import http from '@/utils/request/index.js'
import fileList from '@/pages/synergy/components/fileList.vue'
import TrainingPersonForm from './components/TrainingPersonForm.vue'
import TrainingPersonInfo from './components/TrainingPersonInfo.vue'
import ProcessNodeConfiguration from '@/components/ProcessNodeConfiguration/ProcessNodeConfiguration.vue' // 流程节点配置人员选择弹窗
export default {
  name: 'ErpOmcPayContractManagerForm',
  components: {
    fileList,
    TrainingPersonForm,
    TrainingPersonInfo,
  },
  data() {
    return {
			isSubmit: false, // 控制按钮是否可以点击
      backUpProvisionBroad: '',
      exportTeamId: '',
      index: null,
      id: '',
			trainingType: '', // 申请的类型
      exportWarehouseList: [],
      foldWarehouseList: [],
      basicForm: {},
      formData: [], // 培训人员
			personValue: '', // 培训人员id值
      model: {
        // 基本信息 - 公用
				checkStatus: 0,
        bpmBizTitle: '',
				trainingType: '', // 申请类型
        billNo: '',
        handlerId: '',
        applyDeptId: '',
        createTime: '',
        costTeamId: '', // 申请人所属团队
        trainingCategory: '', // 培训分类
        businessSegment: '',
				trainingObjective: '', // 培训目的
				trainingAddress: '', // 培训地点
				certificateName: '', // 获得证书名称
				trainingStartDate: '', // 培训开始日期
				trainingEndDate: '', // 培训结束日期
				serviceStartDate: '', // 服务开始日期
				trainingServiceLimit: '', // 培训服务期限
				serviceEndDate: '', // 服务结束日期
				trainingFee: '', // 培训费用
				trainingFeeTotal: '', // 培训费用合计
        remark: '', // 备注
				changeRemark: '',
				invalidRemark: '',
        attachment: null, // 附件
      },
      rules: {
				billNo: [{ required: true, message: '请输入单据编号!', trigger: ['blur', 'change'] }],
				finalId: [{ required: true, message: '请选择培训档案!', trigger: ['blur', 'change'] }],
				applyDeptId: [{ required: true, message: '请选择申请部门!', trigger: ['blur', 'change'] }],
				handlerId: [{ required: true, message: '请选择申请人!', trigger: ['blur', 'change'] }],
				createTime: [{ required: true, message: '请选择申请时间!', trigger: ['blur', 'change'] }],
				// 申请人所属团队
        costTeamId: [{ required: true, message: '请选择申请人所属团队!', trigger: ['change', 'blur'] }],
        // 培训分类
        trainingCategory: [{ required: true, message: '请选择培训分类!', trigger: ['change', 'blur'] }],
				// 培训目的
				trainingObjective: [{ required: true, message: '请输入培训目的!', trigger: ['change', 'blur'] }],
				// 培训地点
				trainingAddress: [{ required: true, message: '请输入培训地点!', trigger: ['change', 'blur'] }],
				// 证书名称
				certificateName: [{ required: true, message: '请输入证书名称!', trigger: ['change', 'blur'] }],
				// 培训开始日期
				trainingStartDate: [{ required: true, message: '请选择培训开始日期!', trigger: ['change', 'blur'] }],
				// 培训结束日期
				trainingEndDate: [{ required: true, message: '请选择培训结束日期!', trigger: ['change', 'blur'] }],
				// 服务开始日期
				serviceStartDate: [{ required: true, message: '请选择服务开始日期!', trigger: ['change', 'blur'] }],
				// 培训服务期限
				trainingServiceLimit: [{ required: true, message: '请选择培训服务期限!', trigger: ['change', 'blur'] }],
				// 服务结束日期
				serviceEndDate: [{ required: true, message: '请选择服务结束日期!', trigger: ['change', 'blur'] }],
				trainingFee: [{ required: true, message: '请输入培训费用!', trigger: ['change', 'blur'] }],
				trainingFeeTotal: [{ required: true, message: '请输入培训费用合计!', trigger: ['change', 'blur'] }],
				changeRemark: [{ required: true, message: '请输入变更描述!', trigger: ['change', 'blur'] }],
				invalidRemark: [{ required: true, message: '请输入作废描述!', trigger: ['change', 'blur'] }],
      },
			
			//代码生成后需手动设置流程编码
			flowCode: 'dev_erp_hr_training_apply_001',
			formUrl: '/erp/hr/training/modules/ErpHrTrainingApplyForm',
			beanName: 'erpHrTrainingApplyServiceImpl',
			formUrlMobile: '/pages/synergy/ErpHrTrainingApplyList',
			processId: ''
    }
  },
  onLoad({ id, trainingType }) {
    this.id = id || ''
		if (!id) {
			this.trainingType = trainingType
			var title = trainingType == 'apply'? '培训申请' : trainingType == 'change' ? '培训申请变更' : '培训申请作废'
			uni.setNavigationBarTitle({
				title: title
			})
			if (trainingType != 'apply') {
				this.$set(this.model, 'finalId', null) // 新增培训申请档案
			}
			if (trainingType == 'cancel') {
				this.$set(this.model, 'invalidationProposer', null) // 新增字段
				this.$set(this.model, 'invalidationDepartId', null) // 新增字段
				this.$set(this.model, 'invalidationCreateTime', null) // 新增字段
				this.$set(this.model, 'invalidRemark', '') // 新增字段
			}
			if (trainingType == 'change') {
				this.$set(this.model, 'changeRemark', '') // 新增字段
			}
		}
		
  },
  created() {
    if (this.id) {
      this.initInfo()
			this.initDataList(this.id)
    } else {
      this.initForm()
      this.initBillNo()
    }
    // this.initBuyerInfo()
  },
  computed: {
    ...mapState(['userInfo']),
  },
  methods: {
		// 类型选择
		handleServiceLimitBack () {
			if (this.model.serviceStartDate && this.model.trainingServiceLimit) {
				this.$set(this.model, 'serviceEndDate', moment(this.model.serviceStartDate).add(this.model.trainingServiceLimit, 'day').format('YYYY-MM-DD'))
			} else {
				this.$set(this.model, 'serviceEndDate', '') // 服务结束日期
			}
		},
		handleChangeBack (val) {
			this.handleModelData(val, 'lastBillId')
			this.$set(this.model, 'finalId', val.id)
		},
		handleModelData(val, type) {
			if (val && val.id) {
				// 选择单据 处理原表单数据
				this.$set(this.model, 'invalidationProposer', val.handlerId || '')
				this.$set(this.model, 'invalidationDepartId', val.applyDeptId || '')
				this.$set(this.model, 'invalidationCreateTime', val.createTime || '')
				// this.$set(this.model, 'costTeamId', val.costTeamId || '')
				this.$set(this.model, 'trainingCategory', val.trainingCategory || '') // 培训分类
				this.$set(this.model, 'trainingServiceLimit', val.trainingServiceLimit || '') // 培训服务期限
				this.$set(this.model, 'trainingStartDate', val.trainingStartDate || '') // 培训开始日期
				this.$set(this.model, 'trainingEndDate', val.trainingEndDate || '') // 培训结束日期
				this.$set(this.model, 'serviceStartDate', val.serviceStartDate || '') // 服务开始日期
				this.$set(this.model, 'serviceEndDate', val.serviceEndDate || '') // 服务结束日期
				this.$set(this.model, 'trainingFee', val.trainingFee || '') // 培训费用
				this.$set(this.model, 'trainingFeeTotal', val.trainingFeeTotal || '') // 培训费用合计
				this.$set(this.model, 'trainingObjective', val.trainingObjective) // 培训目的
				this.$set(this.model, 'trainingAddress', val.trainingAddress || '') // 培训地点
				this.$set(this.model, 'certificateName', val.certificateName || '') // 证书名称
				this.$set(this.model, 'remark', val.remark || '') // 备注
				// this.$set(this.model, 'attachment', val.attachment || '') // 附件
				this.$set(this.model, 'finalNo', val.finalNo || '') // 档案编号
				this.initDataList(val[type])// 获取子表数据
			} else {
					// 选择单据 处理原表单数据
				this.$set(this.model, 'invalidationProposer', '')
				this.$set(this.model, 'invalidationDepartId', '')
				this.$set(this.model, 'invalidationCreateTime', '')
				// this.$set(this.model, 'costTeamId', '')
				this.$set(this.model, 'trainingCategory', '')
				this.$set(this.model, 'trainingServiceLimit', '')
				this.$set(this.model, 'trainingStartDate', '')
				this.$set(this.model, 'trainingEndDate', '')
				this.$set(this.model, 'serviceStartDate', '')
				this.$set(this.model, 'serviceEndDate', '') // 服务结束日期
				this.$set(this.model, 'trainingFee', '') // 培训费用
				this.$set(this.model, 'trainingFeeTotal', '') // 培训费用合计
				this.$set(this.model, 'trainingObjective', '')
				this.$set(this.model, 'trainingAddress', '')
				this.$set(this.model, 'certificateName', '')
				this.$set(this.model, 'remark', '')
				// this.$set(this.model, 'attachment', '')
				this.$set(this.model, 'finalNo', '') // 档案编号
				this.$refs.purchaseApply.dataSource = []
			}
			this.handleServiceLimitBack()
		},
    // 新增培训人员
    handleAddMaterial() {
			uni.navigateTo({
				url: `/pages/common/selectPerson?id=${this.personValue}&objectField=personValue&isMulti=true`
			})
    },
		// 计算培训费用合计
		handleTrainingFeeChange () {
			let details = this.formData || []
			let total = ((this.model.trainingFee ? this.model.trainingFee : 0) * details.length).toFixed(2) || '0.00'
			this.$set(this.model, 'trainingFeeTotal', total)
		},
    handleCopyForm([item, index]) {
      this.formData.push({
        ...item,
      })
      this.$u.toast('复制成功')
    },
    handleRemoveForm(item) {
      this.formData = this.formData.filter((i) => i !== item)
			this.personValue = this.formData.map((item, index) => {
        return item.employeeId;
      }).join(",");
    },
    // 获取单据编号
    async initBillNo() {
			var prefix = await ''
			if (this.trainingType == 'apply') {
				prefix = 'PXSQ'
			} else if (this.trainingType == 'change') {
				prefix = 'BGPXSQ'
			} else {
				prefix = 'ZFPXSQ'
			}
      const res = await gainBillNo({prefix, subSystemCode: '02'})
      this.model.billNo = res.result
			if (this.trainingType == 'apply') {
				this.model.bpmBizTitle = this.userInfo?.employee?.name + '-' + this.model.billNo// 标题
			} else if (this.trainingType == 'change') {
				this.$set(this.model, 'bpmBizTitle', this.userInfo?.employee?.name + '-' + this.model.billNo)
			} else {
				this.$set(this.model, 'bpmBizTitle', this.userInfo?.employee?.name + '-' + this.model.billNo)
			}
      // this.model.bpmBizTitle = this.userInfo?.employee?.name + '-' + this.model.billNo //标题
    },
    // 初始化新增需要的数据
    initForm() {
      this.model.handlerId = this.userInfo.empId //当前登录人
      this.model.applyDeptId = this.userInfo.deptId //当前登录人部门
      this.model.createTime = moment().format('YYYY-MM-DD HH:mm') // 申请时间
			this.model.trainingType = this.trainingType
			this.model.trainingServiceLimit = '1094';
    },
		// 编辑查询详情
    async initInfo() {
      const response = await info({ id: this.id })
      const data = response?.result || {}
			this.model = Object.assign({}, data)
			var title = this.model.trainingType == 'apply'? '培训申请' : this.model.trainingType == 'change' ? '培训申请变更' : '培训申请作废'
			if (this.model.trainingType == 'change') {
				this.$set(this.model, 'changeRemark', this.model.changeRemark?this.model.changeRemark: '') // 新增字段
			}if (this.model.trainingType == 'cancel') {
				this.$set(this.model, 'invalidRemark', this.model.invalidRemark?this.model.invalidRemark: '') // 新增字段
			}
			uni.setNavigationBarTitle({
				title: title
			})
			this.trainingType = this.model.trainingType
    },
		// 获取培训人员
		async initDataList(id) {
			var params = {
				billId: id,
				pageNo: 1,
				pageSize: -1
			}
			const response = await http.get('/api/erp/hr/training/erpHrTrainingDetail/allList', params)
			const data = response.success?response.result.records : []
			this.formData = data
		},
    validateForm() {
      return this.$refs.form.validate().then(async () => {
				if (!this.formData.length) {
				  this.$u.toast('请添加培训人员！')
				  return Promise.reject('请添加培训人员！')
				}
        return Promise.resolve()
      })
    },
    async onSubmit() {
      await this.validateForm()
			this.model.applyTeamId = this.model.costTeamId ? this.model.costTeamId : ''
			this.isSubmit = true
      try {
				var url = ''
				if (this.id) {
					url = edit
				} else {
					url = add
				}
        const response = await url({
          ...this.model,
          erpHrTrainingDetailList: this.formData,
        })
        this.$u.toast(response.message)
        if (response.success) {
        	var that = this
        	
					// 获取流程列表
						if (this.model.id) {
							this.getProcessList(this.model.id)
						} else {
						// 判断添加的时候是否有返回id值
							if (response.result) {
								this.getProcessList(response.result)
							}
						
						}
						this.$refs.uToast.show({
							message: response.message,
							type: 'default',
							complete () {
								// that.isSubmit = false
							}
						})
          }
      } finally {
        // this.loading = false
      }
    },
    async onDraft() {
      // await this.validateForm()
      this.isSubmit = true
			this.model.applyTeamId = this.model.costTeamId ? this.model.costTeamId : ''
      try {
      		var url = ''
      		if (this.id) {
      			url = edit
      		} else {
      			url = add
      		}
        const response = await url({
          ...this.model,
          erpHrTrainingDetailList: this.formData,
					
        })
        if (response.success) {
					
					this.$refs.uToast.show({
						message: response.message,
						type: 'default',
						complete () {
							this.isSubmit = false
							if (getCurrentPages().length > 1) {
								uni.navigateBack()
							} else {
								uni.reLaunch({
									url: '/pages/home/home'
								})
							}
							
						}
					})
        } else {
					this.$refs.uToast.show({
						message: response.message,
						type: 'default',
					})
					this.isSubmit = false
				}
      } finally {
        // this.loading = false
      }
    },
		// 获取流程列表
		getProcessList (id) {
			if (this.isSubmit) {
				this.$refs.processConfig.showPopup = true
				this.$refs.processConfig.formUrl = this.formUrl
				this.$refs.processConfig.formUrlMobile = this.formUrlMobile
				this.$refs.processConfig.flowCode = this.flowCode
				this.$refs.processConfig.edit(id, this.processId, this.beanName)
			}
		},
		// 提交流程成功
		onOk () {
			this.$refs.uToast.show({
				message: '提交成功',
				type: 'success',
				complete () {
					if (getCurrentPages().length > 1) {
						uni.navigateBack()
					} else {
						uni.reLaunch({
							url: '/pages/home/home'
						})
					}
					
				}
			})
		},
		getPurchaseDetail (value) {
			if (!value) {
				return false
			}
			erpmngUserIds({empId: value}).then(res => {
				if (res.success) {
					this.formData = res.result.map(val => {
						return {
							departId: val.departId,
							departId_dictText: val.departId_dictText,
							employeeId: val.empId,
							employeeId_dictText: val.realname,
							linkTel: val.phone,
							id: val.empId
						}
					})
				}
			})
			
		},
  },
  watch: {
    'personValue'(newVal, oldVal) {
			if (newVal) {
				this.getPurchaseDetail(newVal)
				// 做个对比,返回回来的值已经保存了,则去除,如果没有则push进去
				
			}
    },
		formData (val) {
			if (val && val.length) {
				let total = ((this.model.trainingFee ? this.model.trainingFee : 0) * val.length).toFixed(2) || '0.00'
				this.$set(this.model, 'trainingFeeTotal', total)
			}
		}
  },
}
</script>

<style scoped lang="scss">
@import url('@/assets/inputStyle.scss');
.trip-form-data {
  ::v-deep {
    .u-form-item__body {
      padding-top: 2px;
      padding-bottom: 2px;
    }
  }
}
.checkbox-item {
  display: flex;
  align-items: center;
}
</style>
